#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

int Day(int year, int month)
{
    int arr[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
    if (((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) && month == 2)
        return arr[month - 1] + 1;
    else
        return arr[month - 1];
}

int main() {
    int year = 0, month = 0;
    while (scanf("%d %d", &year, &month) != EOF)
    {
        int day = Day(year, month);
        printf("%d\n", day);
    }
    return 0;
}